﻿
//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include "UIComponent.h"

#include "IDocument.h"
#include "ElementId.h"
#include "UniIdentity.h"
#include "GbmpQuickCast.h"

namespace gcmp
{
    class IType;
    class IElement;
    class IInstance;
}

namespace Sample
{
    class UICOMPONENT_EXPORT DocumentUtils
    {
        //////////////////////////////////////////////////////////////////////////
        // Element相关接口
    public:
        template<class T> static T* GetElement(const gcmp::IDocument* pDoc, gcmp::ElementId id)
        {
            DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pDoc, L"pDoc为空",L"GDMP",L"2023-10-20");
            return quick_cast<T>(pDoc->GetElement(id));
        }

        // 获得文档下所有类别号为categoryUid的IType
        static std::vector<gcmp::IType*> GetTypiesByCategory(const gcmp::IDocument* pDocument, const gcmp::UniIdentity& categoryUid);

        // 获得文档下所有类别号为categoryUid的Element，不包括Family和Type, 如果 bSort == true, 返回按element id升序数组
        static std::vector<gcmp::IElement*> GetElementsByCategoryExceptFamilyAndType(const gcmp::IDocument* pDoc, 
            const gcmp::UniIdentity& categoryUid, bool excludeLinkElementProxy = true);

        // 得到Family的所有Instance
        static std::vector<const gcmp::IInstance*> GetFamilyInstances(gcmp::IDocument * doc, const std::wstring& familyName);
    };
}

